package com.aeasycredit.test;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class ServerTwo {

	public static void main(String[] args) throws IOException {
		int port = 18080;
		ServerSocket server = new ServerSocket(port);
		System.out.println("server start...");

		Socket socket = server.accept();
		InputStream inputStream = socket.getInputStream();
		BufferedReader read = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"));
		String line;
		StringBuilder sb = new StringBuilder();
		while ((line = read.readLine()) != null) {
			// 注意指定编码格式，发送方和接收方一定要统一，建议使用UTF-8
			sb.append(line);
			break;
		}
		System.out.println("get message from client: " + sb);
		
        OutputStream outputStream = socket.getOutputStream();
        outputStream.write("Hello Client,I get the message.\r\n".getBytes("UTF-8"));
        outputStream.flush();
		
		inputStream.close();
		inputStream.close();
		server.close();
	}

}
